package com.iot.ic.tcp;

/**
 * @Description:返回值及返回描述
 * @author xiuge
 * @date 20(byte)16年7月11日上午9:27:33
 */
public enum DataType {
	
	Time(Data.TIME,6,"时间","device"), 
	Charge(Data.CHARGE,1,"充电状态","device"),
	Power(Data.POWER,1,"电量","device"), 
	Singnalbyteensity(Data.SIGNAL_INTENSITY,1,"信号强度","device"),
	UploadStep(Data.UPLOAD_STEP,2,"上传间隔","device"), 
	Channel(Data.CHANNEL,1,"通道数量","device"),
	Fault(Data.RECORD_TYPE,1,"数据类型","device"),
	Alarm(Data.ALARM,2,"报警","device"),
	IpPort(Data.IP_PORT,6,"IP&Port","device"), 
	SettingFlag(Data.SETTING_FLAG,1,"设置更新标识","device"),
	RomFlag(Data.ROM_FLAG,1,"故障更新标识","device"), 
	RomData(Data.ROM_DATA,128,"升级数据包","device"), 
	RomOrder(Data.ROM_ORDER,2,"升级包序号","device"),
	RomNum(Data.ROM_NUM,2,"升级包总数","devcie"),
	RomVersion(Data.ROM_VERSION,1,"系统版本","device"), 
	
	Humidity(Data.HUMIDITY,1,"时间","channel"), 
	Temperature(Data.TEMPERATURE,4,"充电状态","channel"),
	Max_Hum(Data.MAX_HUM,1,"电量","channel"), 
	Min_Hum(Data.MIN_HUM,1,"信号强度","channel"),
	Max_Tem(Data.MAX_TEM,4,"上传间隔","channel"), 
	Min_Tem(Data.MIN_TEM,4,"通道数量","channel"),
	Sensor_Type(Data.SENSOR_CODE,1,"故障","channel"), 
	
	;
	
	/**
	 * 设备数据类型
	 * 
	 * @author xiuge 2016年10月14日上午9:21:31
	 */
	public class Data {
		public final static byte TIME = 0;
		public final static byte CHARGE = 1;
		public final static byte POWER = 2;
		public final static byte SIGNAL_INTENSITY = 3;
		public final static byte UPLOAD_STEP = 4;
		public final static byte CHANNEL = 5;
		public final static byte RECORD_TYPE = 6;
		public final static byte ALARM = 7;
		public final static byte IP_PORT = 8;
		public final static byte SETTING_FLAG = 9;
		public final static byte ROM_FLAG = 10;
		public final static byte ROM_DATA=11;
		public final static byte ROM_ORDER=12;
		public final static byte ROM_NUM=13;
		public final static byte ROM_VERSION=14;
		public final static byte SETTING_RESPONSE=15;
		public final static byte STEP_WHEN_ALARM=0x10;
		public final static byte ALARM_ENABLE=0x11;


				
		
		public final static byte HUMIDITY = (byte)0x80;
		public final static byte TEMPERATURE = (byte)0x81;
		public final static byte MAX_HUM = (byte)0x82;
		public final static byte MIN_HUM = (byte)0x83;
		public final static byte MAX_TEM = (byte)0x84;
		public final static byte MIN_TEM = (byte)0x85;
		public final static byte SENSOR_CODE = (byte)0x86;
		public final static byte CH_FAULT=(byte)0x87;
		public final static byte TEM_ADJUST = (byte)0x88;
		public final static byte HUM_ADJUST = (byte)0x89;
		public final static byte PM= (byte)0x8A;
		public final static byte FORMALDEHYDE=(byte)0x8B;
		public final static byte CO2=(byte)0x8C;
		
		public final static byte CHANNEL_ID=(byte)0x186;
	};


	private byte type;
	
	private int length;
	
	private String description;
	
	private String tag;
	
	DataType(byte type,int length,String description,String tag) {
		this.type=type;
		this.length=length;
		this.description=description;
		this.tag=tag;
	}
	
	public int getLength(){
		return this.length;
	}
	
	public String getDescription(){
		return this.description;
	}
	
	public String getTag(){
		return this.tag;
	}
	
	public byte getType() {
		return this.type;
	}
	
	
	public static DataType stateOf(byte index) {
		
		for (DataType state:values()) {
			if (state.getLength()==index) {
				return state;
			}
		}
		return null;
	}
	
	public static String getDescByTag(Byte code,String tag){
		if (code==null) {
			return "";
		}
		for (DataType state:values()) {
			if (state.getLength()==code&&state.getTag()==tag) {
				return state.getDescription();
			}
		}
		return "";
	}
	
	
	
	
}
